package com.example.controller;

import com.example.dao.UserMapper;
import com.example.model.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("test")
public class TestController {
    @Resource
    private UserMapper userMapper;

    @GetMapping("users")
    public List<User> selectUsers(){
        /**
         * 查询所有用户
         */
        List<User> users = userMapper.selectList(null);
        return users;
    }

    @GetMapping("user/{id}")
    public User selectUserById(@PathVariable("id")Long userId){
        /**
         * 根据用户id 查询单个用户
         */
        User user = userMapper.selectById(userId);
        return user;
    }
}
